<template>
  <div class="app-container">
    <div class="Search">
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="query">
          <el-form-item v-has="'PLATFROM_TENANT_QUERY'">
            <el-cascader ref="tenantTree" placeholder="所属租户" :props="tenantProps" :options="tenantOptions"
              @change="selectTenant" clearable collapse-tags filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-cascader ref="organTree" placeholder="所属组织" :props="props" :options="organOptions" @change="selectOrgan"
              collapse-tags clearable filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.name" placeholder="促销活动名称" />
          </el-form-item>
          <el-form-item>
            <el-select v-model="query.params.type" placeholder="促销活动类型">
              <el-option v-for="item in query.promotionTypeOptions" :key="item.value" :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-cascader v-model="query.params.merchantId" ref="merchantForm" placeholder="商户编号" :props="merchantProps"
              :options="merchantOptions" @change="chooseMerchantForm(query.params)" style="width:100%" clearable
              collapse-tags filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-select v-model="query.params.auditState" placeholder="审核状态">
              <el-option v-for="item in query.options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.rule" placeholder="促销规则" />
          </el-form-item>
          <el-form-item>
            <el-select v-model="query.params.status" placeholder="状态">
              <el-option v-for="item in query.statusOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-cascader v-model="query.params.storeId" ref="storeForm" placeholder="店铺编号" :props="storeProps"
              :options="storeOptions" @change="chooseStoreForm(query.params)" style="width:100%" clearable collapse-tags
              filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-date-picker v-model="query.params.beginTime" type="daterange" range-separator="至"
              start-placeholder="促销活动开始时间起" end-placeholder="促销活动开始时间止">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-date-picker v-model="query.params.endTime" type="daterange" range-separator="至"
              start-placeholder="促销活动结束时间起" end-placeholder="促销活动结束时间止">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAdd">新增促销活动计划</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </div>

    <div class="block">
      <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
        <el-table-column align="center" label="序号" width="95">
          <template slot-scope="scope">
            {{ scope.$index }}
          </template>
        </el-table-column>
        <el-table-column label="促销活动名称" width="110">
          <template slot-scope="scope">
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column label="关键词" width="110">
          <template slot-scope="scope">
            {{ scope.row.words }}
          </template>
        </el-table-column>
        <el-table-column label="促销活动开始时间" width="110">
          <template slot-scope="scope">
            {{ scope.row.beginTime }}
          </template>
        </el-table-column>
        <el-table-column label="促销活动结束时间" width="110">
          <template slot-scope="scope">
            {{ scope.row.endTime }}
          </template>
        </el-table-column>
        <el-table-column label="商户编号" width="110">
          <template slot-scope="scope">
            {{ scope.row.merchantId }}
          </template>
        </el-table-column>
        <el-table-column label="审核状态" width="110">
          <template slot-scope="scope">
            {{ scope.row.auditState }}
          </template>
        </el-table-column>
        <el-table-column label="审核人" width="110">
          <template slot-scope="scope">
            {{ scope.row.reviewer }}
          </template>
        </el-table-column>
        <el-table-column label="促销规则" width="110">
          <template slot-scope="scope">
            {{ scope.row.rule }}
          </template>
        </el-table-column>
        <el-table-column label="状态" width="110">
          <template slot-scope="scope">
            {{ scope.row.status }}
          </template>
        </el-table-column>
        <el-table-column label="店铺编号" width="110">
          <template slot-scope="scope">
            {{ scope.row.storeId }}
          </template>
        </el-table-column>
        <el-table-column label="促销活动类型" width="110">
          <template slot-scope="scope">
            {{ scope.row.type }}
          </template>
        </el-table-column>

        <el-table-column label="所属租户" width="110">
          <template slot-scope="scope">
            {{ scope.row.tenantId }}
          </template>
        </el-table-column>
        <el-table-column label="所属组织" width="110">
          <template slot-scope="scope">
            {{ scope.row.organId }}
          </template>
        </el-table-column>
        <el-table-column label="创建者" width="110">
          <template slot-scope="scope">
            {{ scope.row.createBy }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" width="110">
          <template slot-scope="scope">
            {{ scope.row.createDate }}
          </template>
        </el-table-column>
        <el-table-column label="更新者" width="110">
          <template slot-scope="scope">
            {{ scope.row.updateBy }}
          </template>
        </el-table-column>
        <el-table-column label="更新时间" width="110">
          <template slot-scope="scope">
            {{ scope.row.updateDate }}
          </template>
        </el-table-column>
        <el-table-column label="备注" width="110">
          <template slot-scope="scope">
            {{ scope.row.remark }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="created_at" label="操作" width="200">
          <template slot-scope="scope">
            <el-link type="primary" icon="el-icon-edit" size="mini"
              @click="handleEdit(scope.$index, scope.row)">修改</el-link>
            <el-link type="danger" icon="el-icon-plus" size="mini"
              @click="handleDelete(scope.$index, scope.row)">删除</el-link>
            <el-link type="warning" icon="el-icon-plus" size="mini"
              @click="handleAddPromotionRule(scope.$index, scope.row)">添加规则</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="block">
      <el-pagination :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" />
    </div>

    <div class="block">
      <!--弹框-->
      <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogFormVisible">
        <el-form :model="form" :rules="PromotionRules" ref="PromotionForm">
          <el-form-item v-if="addForVisible" label="编号" required prop="id">
            <el-input v-model="form.id" disabled placeholder="编号" auto-complete="off" />
          </el-form-item>
          <el-form-item v-has="'PLATFROM_TENANT_QUERY'" prop="tenantId" label="所属租户" placeholder="所属租户" required>
            <el-cascader v-model="form.tenantId" ref="tenantTreeForm" placeholder="所属租户" :props="tenantProps"
              :options="tenantOptions" @change="chooseTenantForm" style="width:100%" clearable collapse-tags
              filterable></el-cascader>
          </el-form-item>
          <el-form-item required prop="organId" label="所属组织">
            <el-cascader v-model="form.organId" ref="organTreeForm" placeholder="所属组织" :props="props"
              :options="organFormOptions" @change="chooseOrganForm" style="width:100%" collapse-tags
              filterable></el-cascader>
          </el-form-item>
          <el-form-item label="促销活动名称" required prop="name">
            <el-input v-model="form.name" placeholder="促销活动名称" auto-complete="off" />
          </el-form-item>
          <el-form-item label="促销规则" required prop="rule">
            <el-input v-model="form.rule" placeholder="促销规则" auto-complete="off" />
          </el-form-item>
          <el-form-item label="促销活动类型" required prop="type">
            <el-select v-model="form.type" placeholder="促销活动类型">
              <el-option v-for="item in query.promotionTypeOptions" :key="item.value" :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="关键词" required prop="words">
            <el-input v-model="form.words" placeholder="关键词" auto-complete="off" />
          </el-form-item>
          <el-form-item label="促销活动开始时间" required prop="beginTime">
            <el-date-picker v-model="form.beginTime" value-format="yyyy-MM-dd mm:HH:ss" type="date"
              placeholder="促销活动开始时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="促销活动结束时间" required prop="endTime">
            <el-date-picker v-model="form.endTime" type="date" value-format="yyyy-MM-dd mm:HH:ss" placeholder="促销活动结束时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="店铺编号" required prop="storeId">
            <el-cascader v-model="form.storeId" ref="storeForm" placeholder="店铺编号" :props="storeProps"
              :options="storeOptions" @change="chooseStoreForm(form)" style="width:100%" clearable collapse-tags
              filterable></el-cascader>
          </el-form-item>

          <el-form-item label="商户编号" required prop="merchantId">
            <el-cascader v-model="form.merchantId" ref="merchantForm" placeholder="商户编号" :props="merchantProps"
              :options="merchantOptions" @change="chooseMerchantForm(form)" style="width:100%" clearable collapse-tags
              filterable></el-cascader>
          </el-form-item>
          <el-form-item label="备注" required prop="remark">
            <el-input v-model="form.remark" placeholder="备注" auto-complete="off" />
          </el-form-item>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleEditSave">确 定</el-button>
        </div>
      </el-dialog>
    </div>


    <div class="block">
      <el-drawer title="促销活动计划" size="68%" :visible.sync="drawer" :direction="direction" :before-close="handleClose">
        <div class="app-container">

          <el-steps :active="step" align-center>
            <el-step title="促销基础信息"></el-step>
            <el-step title="促销规则配置"></el-step>
            <el-step title="促销范围配置"></el-step>
          </el-steps>


          <el-form :model="form" :label-position="'right'" :rules="PromotionRules" ref="PromotionForm">
            <div v-show="step == 1">
              <el-row>
                <el-col :span="12">
                  <el-form-item v-if="addForVisible" label="编号" required prop="id">
                    <el-input v-model="form.id" disabled placeholder="编号" auto-complete="off" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="促销活动名称" style="width:90%" required prop="name">
                    <el-input v-model="form.name" placeholder="促销活动名称" auto-complete="off" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12"><el-form-item v-has="'PLATFROM_TENANT_QUERY'" prop="tenantId" label="所属租户"
                    placeholder="所属租户" required>
                    <el-cascader v-model="form.tenantId" ref="tenantTreeForm" placeholder="所属租户" :props="tenantProps"
                      :options="tenantOptions" @change="chooseTenantForm" style="width:90%" clearable collapse-tags
                      filterable></el-cascader>
                  </el-form-item></el-col>

                <el-col :span="12"> <el-form-item required prop="organId" label="所属组织">
                    <el-cascader v-model="form.organId" ref="organTreeForm" placeholder="所属组织" :props="props"
                      :options="organFormOptions" @change="chooseOrganForm" style="width:100%" collapse-tags
                      filterable></el-cascader>
                  </el-form-item></el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="促销规则" hidden required prop="rule">
                    <el-input v-model="form.rule" suffix-icon="el-icon-date" @focus="handleQueryDroolsRuleList(form)"
                      placeholder="促销规则" style="width:90%" auto-complete="off" />
                  </el-form-item>
                  <el-form-item label="促销规则" required prop="ruleName">
                    <el-input v-model="form.ruleName" suffix-icon="el-icon-date" @focus="handleQueryDroolsRuleList(form)"
                      placeholder="促销规则" style="width:90%" auto-complete="off" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="促销活动类型" required prop="type">
                    <el-select v-model="form.type" style="width:100%" @change="handleInitPromotionTypeForm(form)"
                      placeholder="促销活动类型">
                      <el-option v-for="item in query.promotionTypeOptions" :key="item.value" :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="关键词" required prop="words">
                    <el-input v-model="form.words" placeholder="关键词" style="width:90%" auto-complete="off" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="促销活动时间" required prop="promotionTime">
                    <el-date-picker v-model="form.promotionTime" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss"
                      range-separator="至" start-placeholder="促销活动开始时间" end-placeholder="促销活动结束时间">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="店铺编号" required prop="storeId">
                    <el-cascader v-model="form.storeId" ref="storeForm" placeholder="店铺编号" :props="storeProps"
                      :options="storeOptions" @change="chooseStoreForm(form)" style="width:90%" clearable collapse-tags
                      filterable></el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="商户编号" required prop="merchantId">
                    <el-cascader v-model="form.merchantId" ref="merchantForm" placeholder="店铺编号" :props="merchantProps"
                      :options="merchantOptions" @change="chooseMerchantForm(form)" style="width:90%" clearable
                      collapse-tags filterable></el-cascader>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-form-item label="备注" required prop="remark">
                <el-input type="textarea" v-model="form.remark" placeholder="备注" auto-complete="off" />
              </el-form-item>
            </div>
            <div v-show="step == 2">
              <div v-if="this.form.type === '2'">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="折扣百分比" required prop="promotionMarkdown.discountPercent">
                      <el-input v-model="form.promotionMarkdown.discountPercent" style="width:90%" placeholder="折扣百分比"
                        auto-complete="off" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="优惠计算方式" required prop="promotionMarkdown.markdownType">
                      <el-select v-model="form.promotionMarkdown.markdownType" style="width:100%" placeholder="优惠计算方式">
                        <el-option v-for="item in query.markdownTypeOptions" :key="item.value" :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row>
                  <el-col :span="12">
                    <el-form-item label="最大订货量" required prop="promotionMarkdown.maxNum">
                      <el-input v-model="form.promotionMarkdown.maxNum" style="width:90%" placeholder="最大订货量"
                        auto-complete="off" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="最少订货量" required prop="promotionMarkdown.minNum">
                      <el-input v-model="form.promotionMarkdown.minNum" placeholder="最少订货量" auto-complete="off" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="促销价" required prop="promotionMarkdown.promotionPrice">
                      <el-input v-model="form.promotionMarkdown.promotionPrice" style="width:90%" placeholder="促销价"
                        auto-complete="off" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="销售价" required prop="promotionMarkdown.sellPrice">
                      <el-input v-model="form.promotionMarkdown.sellPrice" placeholder="销售价" auto-complete="off" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>

              <div v-if="this.form.type === '1'">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="满减(额)" required prop="promotionFullReduction.discountPrice">
                      <el-input v-model="form.promotionFullReduction.discountPrice" style="width:90%" placeholder="满减(额)"
                        auto-complete="off" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="满足金额" required prop="promotionFullReduction.meetPrice">
                      <el-input v-model="form.promotionFullReduction.meetPrice" placeholder="满足金额" auto-complete="off" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </div>

            <div v-show="step == 3">

              <el-row>
                <el-col :span="12">
                  <el-form-item required prop="goodsTypeIds" label="促销商品类型">
                    <el-cascader v-model="form.goodsTypeIds" ref="goodsTypeTreeForm" style="width:90%"
                      placeholder="促销商品类型" :props="goodsTypeTreeProps" :options="goodsTypeTreeOptions"
                      @change="getGoodsType(form)" collapse-tags filterable></el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item v-if="this.form.type === '2'" label="促销商品" required prop="productIds">
                    <el-cascader v-model="form.productIds" ref="goodsForm" style="width:100%" placeholder="促销商品"
                      :props="goodsProps" :options="goodsOptions" @change="getGoods(form)" collapse-tags
                      filterable></el-cascader>
                  </el-form-item>
                </el-col>
              </el-row>


              <div class="Search">
                <el-button v-if="this.form.type === '2'" v-has="'GOODS_ADD'" type="success" icon="el-icon-plus"
                  size="mini" @click="handleShowQuerySku">选择促销SKU</el-button>
              </div>

              <div class="block">
                <el-table v-loading="listLoading" :data="promotionRules" element-loading-text="Loading"
                  @selection-change="handleSelectionChange">
                  border fit highlight-current-row>

                  <el-table-column type="selection" width="45">
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="SKU" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.skuName }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="SKU编码" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.goodsCode }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '1'" label="商品名称" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.goodsName }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '1'" label="商品编号" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.id }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="商品编号" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.goodsId }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '1'" label="折扣价格" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.discountPrice }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '1'" label="满足价格" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.meetPrice }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="折扣百分比" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.discountPercent }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="/优惠计算方式" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.markdownType }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="最大订货量" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.maxNum }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="最少订货量" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.minNum }}
                    </template>
                  </el-table-column>

                  <el-table-column v-if="this.form.type === '2'" label="促销价" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.promotionPrice }}
                    </template>
                  </el-table-column>
                  <el-table-column v-if="this.form.type === '2'" label="销售价" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.sellPrice }}
                    </template>
                  </el-table-column>


                  <el-table-column align="center" fixed="right" prop="created_at" label="操作" width="200">
                    <template slot-scope="scope">
                      <el-link type="danger" icon="el-icon-plus" @click="handleRuleDelete(scope.$index, scope.row)">
                        删除
                      </el-link>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </el-form>
        </div>
        <div class="bottom clearfix">
          <el-button v-if="showPrevStepBtn" style="float: right;" type="primary"
            @click="handleGoTOPreStep">上一步</el-button>
          <el-button v-if="showNextStepBtn" style="float: right;" type="primary"
            @click="handleGoTONextStep">下一步</el-button>
          <el-button v-if="showSubmitBtn" style="float: right;" type="primary"
            @click="handleSubmitPromotion">提交</el-button>
        </div>
      </el-drawer>

    </div>


    <div class="block">
      <!--弹框-->
      <el-dialog title="选择促销活动规则" :visible.sync="dialogRuleChooseVisible">
        <div class="block">
          <el-table v-loading="listLoading" :data="droolsRuleList" element-loading-text="Loading" border fit
            highlight-current-row>
            <el-table-column align="center" label="选择" width="35">
              <template slot-scope="scope">
                <el-radio :label="scope.row.id" v-model="form.rule"
                  @change="handelChooseDroolsRule(scope.row)">&nbsp;&nbsp;</el-radio>
              </template>
            </el-table-column>
            <el-table-column label="模板名称" width="210">
              <template slot-scope="scope">
                {{ scope.row.templateName }}
              </template>
            </el-table-column>
            <el-table-column label="状态" width="110">
              <template slot-scope="scope">
                {{ scope.row.status }}
              </template>
            </el-table-column>
            <el-table-column label="备注">
              <template slot-scope="scope">
                {{ scope.row.remark }}
              </template>
            </el-table-column>
          </el-table>
        </div>

      </el-dialog>
    </div>

    <div class="block">
      <!--弹框-->
      <el-dialog title="请选择需要促销的SKU" width="58%" :visible.sync="dialogSkuListVisible">
        <el-table v-loading="listLoading" :data="skuList" element-loading-text="Loading"
          @selection-change="handleSelectionChange">
          border fit highlight-current-row>

          <el-table-column type="selection" fixed="left" width="45">
          </el-table-column>
          <el-table-column label="SKU" width="110">
            <template slot-scope="scope">
              {{ scope.row.goodsName }}
            </template>
          </el-table-column>
          <el-table-column label="SKU编码" width="110">
            <template slot-scope="scope">
              {{ scope.row.goodsCode }}
            </template>
          </el-table-column>
          <el-table-column label="关联商品" width="110">
            <template slot-scope="scope">
              {{ scope.row.goodsId }}
            </template>
          </el-table-column>
          <el-table-column label="库存" width="110">
            <template slot-scope="scope">
              {{ scope.row.stockCount }}
            </template>
          </el-table-column>
          <el-table-column label="价格(单位：分)" width="110">
            <template slot-scope="scope">
              {{ scope.row.price }}
            </template>
          </el-table-column>
          <el-table-column label="备注" width="110">
            <template slot-scope="scope">
              {{ scope.row.remark }}
            </template>
          </el-table-column>
        </el-table>

        <div class="block">
          <el-pagination :current-page="this.query.sku.currentPage" :page-sizes="[10, 20, 30, 40]"
            :page-size="this.query.sku.pageSize" layout="total, sizes, prev, pager, next, jumper"
            :total="this.query.sku.total" @size-change="handleSkuSizeChange" @current-change="handleSkuCurrentChange" />
        </div>

        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogSkuListVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleChooseSkuComfirm">确 定</el-button>
        </div>
      </el-dialog>

    </div>


  </div>
</template>

<script>
import { getList, queryForList, doDelete, doSubmit, doEdit } from '@/api/Promotion/'
import { getList as queryDroolsRulePage } from '@/api/DroolsRules/'
import { queryForList as queryGoods } from '@/api/Goods/'
import { getList as querySkuPage } from '@/api/GoodsPrice/'
import { getStoreList as queryStore } from '@/api/Store/'
import { queryForList as queryMerchant } from '@/api/Merchant/'

import { getList as getOrganPager, querySubordinateOrgan, queryAssigneeOrgan } from '@/api/Organ'
import { getOrganId, getTenantId, getOrganPath, getCurrentLoginUserId, handleBuildTreeDataStruct, getSelectedNodes, getSelectedNodesObject, getSystemErrorCode, getCurrentTimeYYYY_MM_dd_HH_mm_ss } from '@/api/utils'
import { getTenantList, getToken, getOrganList, getDictionary, translateOrganId2OrganName } from '@/utils/auth'
import { getGoodsTypeTree } from '@/api/GoodsType/'

import localStorageUtil from '@/utils/localStorageUtil'
import sessionStorageUtil from '@/utils/sessionStorageUtil'

export default {
  data() {
    return {
      list: null,
      listLoading: true,
      total: 5,
      currentPage: 1,
      pageSize: 10,
      dialogFormVisible: false,
      addForVisible: false,
      direction: 'rtl',
      drawer: false,
      dialogRuleChooseVisible: false,
      droolsRuleList: [],
      dialogSkuListVisible: false,
      skuList: [],
      skuMultipleSelection: [],
      fullReductionList: [],
      markdownList: [],
      promotionRules: [],
      step: 1,
      showNextStepBtn: true,
      showPrevStepBtn: false,
      showSubmitBtn: false,
      form: {
        auditState: '',
        beginTime: '',
        createBy: '',
        createDate: '',
        endTime: '',
        features: '',
        id: '',
        isDeleted: '',
        merchantId: '',
        name: '',
        organId: '',
        organPath: '',
        parentId: '',
        remark: '',
        reviewer: '',
        rule: '',
        ruleName: '',
        promotionFullReduction: {
          meetPrice: '', //满足金额,
          discountPrice: '', //折扣价格,
        },
        promotionMarkdown: {
          discountPercent: '', //折扣百分比,
          markdownType: '', //优惠计算方式：1折扣，2直降优惠价,
          maxNum: '', //最大订货量,
          minNum: '', //最少订货量,
          promotionPrice: '', //促销价,
          sellPrice: '', //销售价,
        },
        skuId: '', //SKU编号,
        productId: '', //产品编号,
        goodsTypeIds: [],
        productIds: [],
        sorted: '',
        status: '',
        storeId: '',
        tenantId: '',
        type: '',
        updateBy: '',
        updateDate: '',
        words: ''
      },
      // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
      titleMap: {
        add: '新增',
        edit: '编辑'
      },
      PromotionRules: {
        features: [{ required: true, message: '不能为空!', trigger: 'blur' }], //

      },
      props: { // 配置项（必选）
        value: 'id',
        label: 'organName',
        children: 'children',
        title: '组织',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      organTreeProps: {
        children: 'children',
        label: 'organName',
        url: 'url'
      },
      tenantProps: { // 配置项（必选）
        value: 'id',
        label: 'organName',
        children: 'children',
        title: '租户',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      goodsTypeTreeProps: { // 配置项（必选）
        value: 'id',
        label: 'typeName',
        children: 'children',
        checkStrictly: true,
        title: '商品类型',
        multiple: true,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      goodsProps: { // 配置项（必选）
        value: 'id',
        label: 'goodsName',
        children: 'children',
        checkStrictly: true,
        title: '商品',
        multiple: true,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      storeProps: { // 配置项（必选）
        value: 'id',
        label: 'storeName',
        children: 'children',
        checkStrictly: true,
        title: '店铺',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      merchantProps: { // 配置项（必选）
        value: 'id',
        label: 'name',
        children: 'children',
        checkStrictly: true,
        title: '商户',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      goodsTypeTreeOptions: [{ id: '1', parentId: '2', typeName: '商品', children: [] }],
      organFormOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      tenantOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      organOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      supplierOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      skuOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      goodsOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      storeOptions: [{ id: '1', parentId: '2', storeName: '店铺', children: [] }],
      merchantOptions: [{ id: '1', parentId: '2', storeName: '店铺', children: [] }],
      organQueryModel: 'selfAndSub',
      supplier: null, //供应商
      goodsType: null, //商品分类
      // // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
      optionData: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      // 新增和编辑弹框标题
      dialogStatus: '',
      query: {
        params: {
          auditState: '', //审核状态,1:审核中,    2.通过，3.不通过, 4.已上线， 5已下线,
          beginTime: '', //促销活动开始时间,
          createBy: '', //创建者,
          createDate: '', //创建时间,
          endTime: '', //促销活动结束时间,
          features: '', //,
          id: '', //,
          isDeleted: '', //,
          merchantId: '', //商户编号,
          name: '', //促销活动名称,
          organId: '', //所属组织,
          organPath: '', //组织路径,
          parentId: '', //,
          remark: '', //,
          reviewer: '', //审核人,
          rule: '', //促销规则,
          sorted: '', //排序,
          status: '', //状态,
          storeId: '', //店铺编号,
          tenantId: '', //所属租户,
          type: '', //促销活动类型(直降、满减满折、套装、赠品、满赠、加价购、秒杀),
          updateBy: '', //更新者,
          updateDate: '', //更新时间,
          words: '', //关键词,
        },
        goods: {
          organId: '',
          organPath: '',
          tenantId: '',
          goodsTypeId: '',
          goodsTypePath: '',
          goodsName: '',
          supplierId: '',
          sys: '',
          goodsTypeIds: [],
          organIds: []
        },
        sku: {
          goodsId: '',
          goodsIds: [],
          goodsName: '',
          goodsCode: '',
          organId: '',
          organPath: '',
          goodsTypeIds: [],
          total: 5,
          currentPage: 1,
          pageSize: 10,
        },
        droolsRule: {
          drlName: '',
          features: '',
          organId: '',
          organPath: '',
          status: '',
          templateContent: '',
          templateName: '',
          tenantId: '',
          total: 5,
          currentPage: 1,
          pageSize: 10,
        },
        store: {
          organIds: [],
          addressId: '', // 关联地址
          enable: '', // 是否生效
          tenantId: '',
          organId: '', // 所属组织
          organPath: '', // 组织路径
          storeName: '', // 店铺名称
        },
        merchant: {
          id: '', //商户名称
          name: '', //商户名称
          type: '', //商户类型,1 企业商户，2, 个体商户， 3 个人商户
          organId: '', //
          organPath: '', //
          isMain: '' //是否主商户，0 为从商户，1为主商户
        },
        promotionTypeOptions: [],
        timeValue: '',
        markdownTypeOptions: [{
          value: '1',
          label: '折扣'
        }, {
          value: '2',
          label: '直降优惠价'
        }],
        options: [{
          value: '1',
          label: '黄金糕'
        }, {
          value: '2',
          label: '双皮奶'
        }],
        statusOptions:[],
        value: ''
      }
    }
  },
  created() {
    this.initOrganTree(() => {
      this.setOrganQueryType()
    }, getOrganPath())
    this.initGoodsTypeTree()
    this.initOrganFormTree()
    this.handleFiltTenant()
    this.handleQueryStore()
    this.handleQueryMerchant()
    this.handleInitPromotionType()
    this.handleBuildStatusOptions()
    this.fetchData()
  },
  methods: {
    createOrganQuery() {
      // 选中了租户
      let tenantSelected = this.$refs['tenantTree'] && this.$refs['tenantTree'].getCheckedNodes() || []
      let organSelected = this.$refs['organTree'] && this.$refs['organTree'].getCheckedNodes() || []
      let that = this
      this.query.params.organId = null
      if (tenantSelected.length && tenantSelected[0]) {
        this.query.params.tenantId = tenantSelected[0].data.id
        if (organSelected.length && organSelected[0]) {
          if (this.props.multiple) {
            this.query.params.organId = null
            this.query.params.organIds = []
            if (organSelected.length && organSelected[0]) {
              organSelected.forEach(function (element) {
                that.query.params.organIds.push(element.data.id)
              })
            }
          } else if (organSelected.length && organSelected[0]) {
            this.query.params.organPath = organSelected[0] && organSelected[0].data.organPath
          }
        }
      } else {
        this.query.params.tenantId = getTenantId()
        if (organSelected.length && organSelected[0]) {
          if (this.props.multiple) {
            this.query.params.organId = null
            this.query.params.organIds = []
            if (organSelected.length && organSelected[0]) {
              organSelected.forEach(function (element) {
                that.query.params.organIds.push(element.data.id)
              })
            }
          } else if (organSelected.length && organSelected[0]) {
            this.query.params.organPath = organSelected[0].data.organPath
          }
        }
      }
      this.query.params.organId = this.query.params.organId || getOrganId()
      this.query.params.organPath = this.query.params.organPath || getOrganPath()
    },
    fetchData() {
      this.listLoading = true
      this.createOrganQuery()
      this.currentPage = this.currentPage || 1
      this.pageSize = this.pageSize || 10
      getList(this.query.params, this.currentPage, this.pageSize).then(response => {
        const data = response.data
        if (!data.entities || typeof data.successful != 'undefined') {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
        this.total = data.totalCount
        this.pageSize = data.pageSize
        this.currentPage = data.currentPage
        this.list = data.entities
        this.listLoading = false
      })
    },

    handleSizeChange(val) {
      this.currentPage = 1
      this.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.fetchData()
    },
    // 新增
    handleAdd() {
      // 显示弹框
      this.drawer = true
      // 新增弹框标题
      this.dialogStatus = 'add'
      this.checkPrevStepShow()
      this.checkNextStepShow()
      this.form.auditState = '1'
      this.form.beginTime = ''
      this.form.createBy = getCurrentLoginUserId()
      this.form.createDate = getCurrentTimeYYYY_MM_dd_HH_mm_ss()
      this.form.endTime = ''
      this.form.features = ''
      this.form.id = ''
      this.form.merchantId = ''
      this.form.name = ''
      this.form.organId = getOrganId()
      this.form.organPath = getOrganPath()
      this.form.parentId = ''
      this.form.remark = ''
      this.form.reviewer = '1'
      this.form.rule = ''
      this.form.sorted = '1'
      this.form.status = '1'
      this.form.storeId = ''
      this.form.tenantId = getTenantId()
      this.form.type = ''
      this.form.updateBy = getCurrentLoginUserId()
      this.form.updateDate = getCurrentTimeYYYY_MM_dd_HH_mm_ss()
      this.form.words = ''
      this.addForVisible = false
    },
    // 编辑
    handleEdit(index, row) {
      this.form.auditState = row.auditState
      this.form.beginTime = row.beginTime
      this.form.createBy = row.createBy
      this.form.createDate = row.createDate
      this.form.endTime = row.endTime
      this.form.features = row.features
      this.form.id = row.id
      this.form.isDeleted = row.isDeleted
      this.form.merchantId = row.merchantId
      this.form.name = row.name
      this.form.organId = row.organId
      this.form.organPath = row.organPath
      this.form.parentId = row.parentId
      this.form.remark = row.remark
      this.form.reviewer = row.reviewer
      this.form.rule = row.rule
      this.form.sorted = row.sorted
      this.form.status = row.status
      this.form.storeId = row.storeId
      this.form.tenantId = row.tenantId
      this.form.type = row.type
      this.form.updateBy = row.updateBy
      this.form.updateDate = row.updateDate
      this.form.words = row.words
      this.addForVisible = true
      // 显示弹框
      this.dialogFormVisible = true
      // 编辑弹框标题
      this.dialogStatus = 'edit'
    },
    handleDelete(index, row) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        doDelete(row.id).then(response => {
          const data = response.data
          console.log(data)
          if (data.status == 1) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.fetchData();
          } else if (data.status == 403) {
            this.$message({
              type: 'warning',
              message: data.description
            })
          } else {
            this.$message({
              type: 'info',
              message: '操作失败!'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleEditSave() {
      doEdit(this.form).then(response => {
        const data = response.data
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.fetchData();
          this.dialogFormVisible = false
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }

        this.listLoading = false
        this.dialogFormVisible = false
      })
    },
    handleReset() {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    initOrganTree(fn, filter, that) {
      this.listLoading = true
      let data = getOrganList()
      if (filter) {
        data = data.filter(function (item, index) {
          return item.organPath.indexOf(filter) >= 0
        })
      }
      if (that && that.organFormOptions && that.organFormOptions.length >= 0) {
        that.organFormOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
      } else {
        this.organOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
      }
      this.listLoading = false
      if (fn) {
        fn()
      }
    },
    initOrganFormTree(fn, filter) {
      this.initOrganTree(fn, filter, this)
    },
    setOrganQueryType() {
      this.organQueryModelChange(localStorageUtil.fetch("SYSTEM_SETTING_ORGAN_QUERY_MODEL"))
    },
    selectOrgan(nodes) {
      let nodesInfo = this.$refs['organTree'].getCheckedNodes()
      let that = this
      this.query.params.organPath = ''
      this.query.params.organIds = []
      if (this.props.multiple) {
        this.query.params.organIds = []
        if (nodesInfo.length) {
          nodesInfo.forEach(function (element) {
            that.query.params.organIds.push(element.data.id)
          })
        }
      } else if (nodesInfo.length) {
        this.query.params.organPath = nodesInfo[0].data.organPath
      }
    },
    selectTenant(nodes) {
      let nodesInfo = this.$refs['tenantTree'].getCheckedNodes()
      let that = this
      this.query.params.tenantId = ''
      this.query.params.tenantIds = []
      this.query.params.organId = null
      this.query.params.organIds = []
      this.query.params.organPath = null

      if (this.tenantProps.multiple) {
        this.query.params.tenantIds = []
        if (nodesInfo.length) {
          nodesInfo.forEach(function (element) {
            that.query.params.tenantIds.push(element.data.id)
          })
        }
      } else if (nodesInfo.length) {
        this.query.params.tenantId = nodesInfo[0].data.id
        this.initOrganTree(function () {
          that.setOrganQueryType()
        }, nodesInfo[0].data.organPath)
      } else {
        this.initOrganTree(function () {
          that.setOrganQueryType()
        })
      }
    },
    chooseTenantForm(nodes) {
      let nodesInfo = this.$refs['tenantTreeForm'].getCheckedNodes()
      this.form.tenantId = null
      let that = this
      if (nodesInfo.length) {
        this.form.tenantId = nodesInfo[0].data.id
        this.initOrganFormTree(function () {
          that.setOrganQueryType()
        }, nodesInfo[0].data.organPath, this.organFormOptions)
      } else {
        this.initOrganFormTree(function () {
          that.setOrganQueryType()
        }, null, this.organFormOptions)
      }
    },
    organQueryModelChange(organQueryModel) {
      if (organQueryModel == 'selected') {
        this.props.multiple = true
      } else if (organQueryModel == 'selfAndSub') {
        this.props.multiple = false
      }
    },
    chooseOrganForm(nodes) {
      let nodesInfo = this.$refs['organTreeForm'].getCheckedNodes()
      if (nodesInfo[0]) {
        this.form.organPath = nodesInfo[0].data.organPath
        this.form.organId = nodesInfo[0].data.id
        this.form.tenantId = nodesInfo[0].data.tenantId
      }
    },
    handleFiltTenant() {
      let data = getOrganList()
      this.tenantOptions = data.filter(function (item, index) {
        return item.type == 0 || item.type == 1;
      })
    },
    handleInitPromotionType() {
      const datas = getDictionary()
      let data = datas.filter(function (item, index) {
        return item.bigType === "PromotionType" && item.parentId != '0';
      })

      let promotionTypeOptions = [];
      for (let i = 0; i < data.length; i++) {

        let option = {}
        option['value'] = data[i].value
        option['label'] = data[i].desc
        promotionTypeOptions.push(option)
      }
      this.query.promotionTypeOptions = promotionTypeOptions

    },
    handleClose(done) {
      this.$confirm('确认关闭[促销活动计划]新增操作吗？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },
    handleQueryDroolsRuleList(node) {
      this.dialogRuleChooseVisible = true
      this.query.droolsRule.organPath = node.organPath || getOrganPath()
      this.query.droolsRule.tenantId = node.tenantId || getTenantId()
      this.query.droolsRule.pageSize = this.query.droolsRule.pageSize || 10
      this.query.droolsRule.currentPage = this.query.droolsRule.currentPage || 1
      this.query.droolsRule.type = 1
      queryDroolsRulePage(this.query.droolsRule, this.query.droolsRule.currentPage, this.query.droolsRule.pageSize).then(response => {
        const data = response.data
        this.total = data.totalCount
        this.query.droolsRule.pageSize = data.pageSize
        this.query.droolsRule.currentPage = data.currentPage
        this.droolsRuleList = data.entities
        this.listLoading = false
      })

    },
    initGoodsTypeTree() {
      this.listLoading = true
      getGoodsTypeTree({ organId: getOrganId() }).then(response => {
        console.log(response)
        const data = response.data.data
        this.goodsTypeTreeOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
        this.listLoading = false
      })
    },
    getGoodsType(form) {
      let nodesInfo = this.$refs['goodsTypeTreeForm'].getCheckedNodes()
      if (this.goodsTypeTreeProps.multiple) {
        let goodsTypeIds = []
        if (nodesInfo && nodesInfo.length >= 1) {
          for (let i = 0; i < nodesInfo.length; i++) {
            goodsTypeIds.push(nodesInfo[i].data.id)
          }
          form.goodsTypeIds = goodsTypeIds
          this.handleQueryGoods(form)
        }
      } else {
        form.goodsTypeId = nodesInfo[0].data.id
        form.goodsTypePath = nodesInfo[0].data.typePath
      }

    },
    getGoods(form) {
      let nodesInfo = this.$refs['goodsForm'].getCheckedNodes()
      if (this.goodsProps.multiple) {
        let goodsIds = []
        if (nodesInfo && nodesInfo.length >= 1) {
          for (let i = 0; i < nodesInfo.length; i++) {
            goodsIds.push(nodesInfo[i].data.id)
          }
          form.productIds = goodsIds
        }
      } else {
        form.goodsId = nodesInfo[0].data.id
      }
    },
    chooseMerchantForm(form) {
      let nodesInfo = this.$refs['merchantForm'].getCheckedNodes()
      if (this.merchantProps.multiple) {
        let merchantIds = []
        if (nodesInfo && nodesInfo.length >= 1) {
          for (let i = 0; i < nodesInfo.length; i++) {
            merchantIds.push(nodesInfo[i].data.id)
          }
          form.merchantIds = merchantIds
        }
      } else {
        form.merchantId = nodesInfo[0].data.id
      }
    },
    chooseStoreForm(form) {
      let nodesInfo = this.$refs['storeForm'].getCheckedNodes()
      if (this.storeProps.multiple) {
        let storeIds = []
        if (nodesInfo && nodesInfo.length >= 1) {
          for (let i = 0; i < nodesInfo.length; i++) {
            storeIds.push(nodesInfo[i].data.id)
          }
          form.storeIds = storeIds
        }
      } else {
        form.storeId = nodesInfo[0].data.id
      }
    },
    handelChooseDroolsRule(droolsRule) {
      this.form.rule = droolsRule.id
      this.form.ruleName = droolsRule.templateName
    },
    handleQueryGoods(goodsQuery) {
      let that = this
      this.query.goods.organId = getOrganId()
      this.query.goods.tenantId = getTenantId()
      this.query.goods.organPath = getOrganPath()
      this.query.goods.goodsTypeIds = goodsQuery.goodsTypeIds

      queryGoods(this.query.goods).then(response => {
        const gateway = response.data
        if (gateway.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          debugger
          this.goodsOptions = gateway.data
          if (that.form.type === '1') { // 此时为满减
            // this.promotionRules = gateway.data
            this.handleFullReduction(gateway.data)
          }
        } else {
          this.$message({
            type: 'info',
            message: gateway.description || getSystemErrorCode(gateway.status)
          })
        }
      })
    },
    handleQuerySkuPage() {

      this.query.sku.goodsIds = this.form.productIds
      this.query.sku.goodsTypeIds = this.form.goodsTypeIds
      this.query.sku.organId = this.form.organId || getOrganId()
      this.query.sku.organPath = this.form.organPath || getOrganPath()
      this.query.sku.tenantId = this.form.tenantId || getTenantId()

      this.query.sku.pageSize = this.query.sku.pageSize || 20
      this.query.sku.currentPage = this.query.sku.currentPage || 1

      querySkuPage(this.query.sku, this.query.sku.currentPage, this.query.sku.pageSize).then(response => {
        const data = response.data
        this.query.sku.total = data.totalCount
        this.query.sku.pageSize = data.pageSize
        this.query.sku.currentPage = data.currentPage
        this.skuList = data.entities
        this.listLoading = false
      })
    },
    handleSkuSizeChange(val) {
      this.query.sku.currentPage = 1
      this.query.sku.pageSize = val
      this.handleQuerySkuPage()
    },
    handleSkuCurrentChange(val) {
      this.query.sku.currentPage = val
      this.handleQuerySkuPage()
    },
    handleShowQuerySku() {
      this.dialogSkuListVisible = true
      this.handleQuerySkuPage()
    },
    handleSelectionChange(val) {
      this.skuMultipleSelection = val;
    },
    handleChooseSkuComfirm() {
      if (this.skuMultipleSelection.length <= 0) {
        this.$message({
          type: 'warning',
          message: '请选择SKU!'
        })
        return;
      }
      this.handleInitPromotionTypeForm(this.form)
    },
    handleChooseSku() {
      this.dialogSkuListVisible = false
    },
    handleFullReduction(goods) {
      let fullReductionList = []
      for (let i = 0; i < goods.length; i++) {
        fullReductionList.push({
          productId: goods[i].id,
          goodsName: goods[i].goodsName,
          goodsCode: goods[i].goodsCode,
          goodsTypeId: goods[i].goodsTypeId,
          meetPrice: this.form.promotionFullReduction.meetPrice,
          discountPrice: this.form.promotionFullReduction.discountPrice
        })
      }
      this.promotionRules = fullReductionList
      this.fullReductionList = fullReductionList
    },
    handleInitPromotionTypeForm(form) {
      if (form.type === '1') {
        //初始化满减
        //this.form['promotionFullReduction'] = 
        // this.form.promotionMarkdown = null
        let fullReductionList = []
        for (let i = 0; i < this.skuMultipleSelection.length; i++) {
          fullReductionList.push({
            skuId: this.skuMultipleSelection[i].id,
            productId: this.skuMultipleSelection[i].goodsId,
            skuName: this.skuMultipleSelection[i].goodsName,
            goodsCode: this.skuMultipleSelection[i].goodsCode,
            goodsTypeId: this.skuMultipleSelection[i].goodsTypeId,
            meetPrice: this.form.promotionFullReduction.meetPrice,
            discountPrice: this.form.promotionFullReduction.discountPrice
          })
        }
        this.promotionRules = fullReductionList
        this.fullReductionList = fullReductionList
      } else if (form.type === '2') {
        let markdownList = []
        for (let i = 0; i < this.skuMultipleSelection.length; i++) {
          markdownList.push({
            skuId: this.skuMultipleSelection[i].id,
            productId: this.skuMultipleSelection[i].goodsId,
            skuName: this.skuMultipleSelection[i].goodsName,
            goodsCode: this.skuMultipleSelection[i].goodsCode,
            goodsTypeId: this.skuMultipleSelection[i].goodsTypeId,
            discountPercent: this.form.promotionMarkdown.discountPercent,
            markdownType: this.form.promotionMarkdown.markdownType, //优惠计算方式：1折扣，2直降优惠价,
            maxNum: this.form.promotionMarkdown.maxNum, //最大订货量,
            minNum: this.form.promotionMarkdown.minNum, //最少订货量,
            promotionPrice: this.form.promotionMarkdown.promotionPrice, //促销价,
            sellPrice: this.form.promotionMarkdown.sellPrice, //销售价,
          })
        }
        this.promotionRules = markdownList
        this.markdownList = markdownList
        //初始化直降
      } else if (form.type === '3') {
        //初始化秒杀
      }

    },
    handleQueryStore() {
      this.query.store.organId = getOrganId()
      this.query.store.organPath = getOrganPath()
      this.query.store.tenantId = getTenantId()
      queryStore(this.query.store).then(response => {
        const gateway = response.data
        if (gateway.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.storeOptions = gateway.data

        } else {
          this.$message({
            type: 'info',
            message: gateway.description || getSystemErrorCode(gateway.status)
          })
        }
      })
    },
    handleQueryMerchant() {
      this.query.merchant.organId = getOrganId()
      this.query.merchant.organPath = getOrganPath()
      this.query.merchant.tenantId = getTenantId()
      queryMerchant(this.query.merchant).then(response => {
        const gateway = response.data
        if (gateway.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.merchantOptions = gateway.data

        } else {
          this.$message({
            type: 'info',
            message: gateway.description || getSystemErrorCode(gateway.status)
          })
        }
      })
    },
    handleAddPromotionRule(index, row) {
      if (row.type == 1) {
        //初始化直降
        //this.form['promotionFullReduction'] = 
        // this.form.promotionMarkdown = null

      } else if (row.type == 2) {
        // this.form['promotionMarkdown'] = 
        // this.form.promotionFullReduction = null

        //初始化直降
      }
    },
    handleSubmitPromotion() {

      if (this.form.type == '1') {
        this.form['fullReductionVOList'] = this.fullReductionList
      } else if (this.form.type === '2') {
        this.form['markdownVOList'] = this.markdownList
      }
      this.form.beginTime = this.form.promotionTime[0]
      this.form.endTime = this.form.promotionTime[1]
      doSubmit(this.form).then(response => {
        const gateway = response.data
        if (gateway.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.fetchData();
          this.dialogFormVisible = false
        } else {
          this.$message({
            type: 'info',
            message: gateway.description || getSystemErrorCode(gateway.status)
          })
        }
        this.listLoading = false
        this.dialogFormVisible = false
      })
    },
    handleGoTONextStep() {
      debugger
      if (this.step < 3) {
        this.step = ++this.step
      } else {
      }
      this.checkPrevStepShow()
      this.checkNextStepShow()
      this.checkSubmitShow()
    },
    checkPrevStepShow() {
      if (this.step > 1) {
        this.showPrevStepBtn = true
      } else {
        this.showPrevStepBtn = false
      }
    },
    checkNextStepShow() {
      if (this.step < 3) {
        this.showNextStepBtn = true
      } else {
        this.showNextStepBtn = false
      }
    },
    checkSubmitShow() {
      if (this.step == 3) {
        this.showSubmitBtn = true
      } else {
        this.showSubmitBtn = false
      }
    },
    handleGoTOPreStep() {
      debugger
      if (this.step > 1) {
        this.step = --this.step
      }
      this.checkPrevStepShow()
      this.checkNextStepShow()
      this.checkSubmitShow()
    },
    handleRuleDelete(index, row) {
      debugger
      this.promotionRules.splice(index, 1)
    },
    handleBuildStatusOptions() {
      const datas = getDictionary()
      let data = datas.filter(function (item, index) {
        return item.bigType === "BizEntity" && item.parentId != '0';
      })
      let statusOptions = [];
      for (let i = 0; i < data.length; i++) {

        let option = {}
        option['value'] = data[i].value
        option['label'] = data[i].desc
        statusOptions.push(option)
      }
      this.query.statusOptions = statusOptions
    },
  }
}
</script>
